// components/searchForm/searchForm.js
const app = getApp()
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    searchTop: false,
    showResult: false,
    result: [],
    hasResult: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    focusInput: function (e) {
      this.setData({
        searchTop: true
      })
    },
    blurInput: function (e) {
      if (e.detail.value == '') {
        this.setData({
          searchTop: false,
          showResult: false,
        })
      } else {
        const url = `https://api.douban.com/v2/book/search?q=${e.detail.value}`
        app
          .doGet(url)
          .then(res => res.data)
          .then(res => {
            this.setData({
              showResult: true,
              result: res.books,
              hasResult: res.count > 0
            })
          })
      }
    }
  }
})
